<template>
  <div class="swiper">
    <swiper
      :slidesPerView="1"
      :autoplay="{ delay: 30000, disableOnInteraction: false }"
      :navigation="true"
      :pagination="{ type: 'bullets', clickable: true }"
      :scrollbar="{ draggable: false }"
      :space-between="30"
      :modules="modules"
      :loop="true"
      @mouseenter="enter"
      @mouseleave="leave"
      @swiper="onSwiper"
      @slideChange="onSlideChange"
    >
      <swiper-slide v-for="(item, index) in swiperData" :key="index" class="swiperItem">
        <div class="Sample">
          <div class="left">
            <div class="title">Case study</div>
            <div class="size">
              Bicycle accident case: The vehicle enters andexits the garage and is on a business due
              to improper driving.lt is covered by the claim
            </div>
          </div>
          <div class="rigth">
            <div class="bakImg"></div>
            <div class="Img">
              <img
                :src="$t(`messages.WarrantySerachData.imageList[${index}].image`)"
                alt=""
                srcset=""
              />
            </div>
          </div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { WarrantySerachImage } from '@/http/api/WarrantySerach.js'
import Zh from '@/assets/i18n/langs/zh.js'
import En from '@/assets/i18n/langs/en.js'
import { toRaw, ref, reactive, onMounted } from 'vue'
import { Swiper, SwiperSlide } from 'swiper/vue'
import 'swiper/css'
import 'swiper/scss/navigation'
import 'swiper/scss/pagination'
import { Autoplay, Navigation, Scrollbar, A11y } from 'swiper/modules'
const props = defineProps()
const router = useRouter()
let modules = [Autoplay, Navigation, Scrollbar, A11y]
//定义swiperNew,目的获取非响应式swiper
let swiperNew = ''

//鼠标移入
const enter = () => {
  swiperNew.autoplay.stop()
}
//鼠标移出
const leave = () => {
  swiperNew.autoplay.start()
}
const onSwiper = (swiper) => {
  // console.log(swiper);

  swiperNew = toRaw(swiper) //拿到swiper对象再转换为非响应式
}
const onSlideChange = () => {
  // console.log("slide change");
}
let pageData = reactive({
  page: 1,
  size: 50
})
let swiperData = ref([])
const getData = async () => {
  let res = await WarrantySerachImage(pageData)
  Zh.messages.WarrantySerachData.imageList = res.res.map((item, index) => {
    return {
      image: item.imageZh
    }
  })
  En.messages.WarrantySerachData.imageList = res.res.map((item, index) => {
    return {
      image: item.imageEn
    }
  })

  swiperData.value = res.res
}
onMounted(() => {
  getData()
})
</script>
<style lang="scss" scoped>
.swiper {
  width: 100%;
  height: 100%;
  margin: 0;
  img {
    width: 100%;
    height: 100%;
  }

  .swiperItem {
    height: 100%;
    width: 100% !important;
    cursor: pointer;
  }
}

::v-deep(.swiper-pagination-bullet) {
  //修改分页器圆点大小
  width: 8px;
  height: 8px;
  background-color: #fff;
}

.swiper-horizontal > .swiper-pagination-bullets .swiper-pagination-bullet,
::v-deep(.swiper-pagination-horizontal.swiper-pagination-bullets) .swiper-pagination-bullet {
  // 分页器远点之间的距离
  margin: 0 10px;
}

::v-deep(.swiper-button-prev),
::v-deep(.swiper-button-next) {
  color: black;
  width: 70px;
  height: 70px;
  background: #ffffff;
  border-radius: 35px;
}

.swiper {
  background: #050607;
  height: 1080px;
}
.Sample {
  padding: 150px 150px 220px 190px;
  height: 100%;
  display: flex;
}
.left {
  width: 700px;
  margin-top: 350px;
  margin-right: 150px;
  .size {
    color: white;
  }
}
.rigth {
  position: relative;
}
.bakImg {
  width: 350px;
  height: 550px;
  background: #ffdd00;
  position: absolute;
  top: 60px;
  left: 0;
}
.Img {
  width: 660px;
  height: 580px;
  position: absolute;
  top: 0;
  left: 30px;
  .img {
    width: 100%;
    height: 100%;
  }
}
</style>

